#include <avr/interrupt.h>
#include <avr/io.h>
#include "common.h"
#include "LED.h"


int main(){

	uint16_t pulse_width=0;
    /** Disable default prescaler to make processor speed 8 MHz. */
    CLKPR = (1<<CLKPCE);
    CLKPR = 0x00;	
	

	DDRC |= (1<<PORTC5); //Enable output for PSWM

	TCCR3B = (0<<CS30) | (1<<CS31) | (0<<CS32) | (1<<WGM33) | (1<<WGM32); 
	TCCR3A = (0<<WGM30) | (1<<WGM31) | (1<<COM3B1) | (0<<COM3B0);

	ICR3 = 40000; // The max width for the PWM (TOP)


	init_LED_D2();
	init_LED_D5();

	sei(); /** enable global interrupts **/

	pulse_width=4000;
	on_LED(LED_D2_GREEN);

	while (1){
		pulse_width+=100;
		if (pulse_width>4000){
			pulse_width=0;
			on_LED(LED_D5_GREEN);
			delayFor(500);
			off_LED(LED_D5_GREEN);
		}
		OCR3B = pulse_width;
		delayFor(500);
	}
}